package com.lijin.service.impl;

import com.lijin.dao.LotteryInformationDao;
import com.lijin.domain.entity.Lottery;
import com.lijin.domain.json.LotteryData;
import com.lijin.service.LotteryInformationService;
import com.lijin.service.LotteryService;
import com.lijin.service.SchedulerService;
import java.util.List;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * Created by gold-jx on 2017/10/24.
 */
@Service
@Slf4j
public class SchedulerServiceImpl implements SchedulerService {

  @Autowired
  private LotteryInformationService lotteryInformationService;

  @Autowired
  private LotteryService lotteryService;

  @Autowired
  private RedisTemplate redisTemplate;

  @Autowired
  private LotteryInformationDao lotteryInformationDao;

  /**
   * 福彩3D
   */
  @Override
  public void scheduler_fc3d(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("X3D", 3, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 排列3
   */
  @Override
  public void scheduler_pl3(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("PL3", 3, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 北京PK10
   */
  @Override
  public void scheduler_bjpk10(String code) {

    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_BJPK10", 3, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }
      }

    }

  }

  /**
   * 重庆时时彩
   */
  @Override
  public void scheduler_cqssc(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_CQSSC", 3, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 天津时时彩
   */
  @Override
  public void scheduler_tjssc(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_TJSSC", 3, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 新疆时时彩
   */
  @Override
  public void scheduler_xjssc(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_XJSSC", 3, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 幸运飞艇
   */
  @Override
  public void scheduler_xyft(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_XYFT", 3, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 广东11选5
   */
  @Override
  public void scheduler_gd11x5(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_GDD11", 5, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 广东快乐10分
   */
  @Override
  public void scheduler_gdklsf(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_GDKL10F", 5, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }
      }

    }

  }

  /**
   * 重庆快乐10分
   */
  @Override
  public void scheduler_cqklsf(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_CQKL10F", 5, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }


  /**
   * 江西11选5
   */
  @Override
  public void scheduler_jx11x5(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_JXD11", 5, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 上海11选5
   */
  @Override
  public void scheduler_sh11x5(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_SHD11", 5, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }


  /**
   * 上海时时乐
   */
  @Override
  public void scheduler_shssl(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_SHSSL", 3, lotteryList.get(i).getLotteryUrl());

        }else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 安徽11选5
   */
  @Override
  public void scheduler_ah11x5(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_AHD11", 5, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 六合彩
   */
  @Override
  public void scheduler_six(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("MARK_SIX", 3, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 山东11选5
   */
  @Override
  public void scheduler_sd11x5(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_SDD11", 5, lotteryList.get(i).getLotteryUrl());

        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }

  }

  /**
   * 广西快3
   * caijingwang
   */
  @Override
  public void scheduler_allk3(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation(code, 3, lotteryList.get(i).getLotteryUrl());
        } else {
          addkindlottery(code,lotteryList,i);
        }

      }

    }
  }

  @Override
  public void scheduler_bj28(String code) {
    //1.根据编码查彩种表
    List<Lottery> lotteryList = lotteryService.findByCode(code);
    //1.1彩种列表为空
    if (lotteryList == null) {
      log.error("查询彩种列表为空");
    } else {
      //2.遍历
      for (int i = 0; i < lotteryList.size(); i++) {
        if ("ydniu".equals(lotteryList.get(i).getSource())) {
          lotteryInformationService
              .addyiDingLotteryInformation("HF_BJ28", 5, lotteryList.get(i).getLotteryUrl());
        } else {
          addkindlottery(code,lotteryList,i);
        }

      }
    }
  }

  @Override
  public void scheduler_caijing() {
    lotteryInformationService.addCaiJingWangLotteryInformation();
  }

  @Override
  public void scheduler_caipiao55() {
    lotteryInformationService.addCaiPiao55LotteryInformation();
  }

  @Override
  public void scheduler_caipiaoqq() {
    lotteryInformationService.addCaiPiaoqqLotteryInformation();
  }

  @Override
  public void scheduler_checkData() {
    Set<LotteryData> set = redisTemplate.opsForSet().members("setLotteryData");
    lotteryInformationService.addcheck_data(set);
  }

  public void addkindlottery(String code,List<Lottery> lotteryList,int i){

    if ("5gcp".equals(lotteryList.get(i).getSource())) {
      lotteryInformationService
          .add5gcpLotteryInformation(code, lotteryList.get(i).getLotteryUrl());
    } else if ("fenghuangwang".equals(lotteryList.get(i).getSource())) {
      lotteryInformationService
          .addFengHuangLotteryInformation(code, lotteryList.get(i).getLotteryUrl());

    } else if ("cpy".equals(lotteryList.get(i).getSource())) {
      lotteryInformationService
          .addCaiPiaoYunLotteryInformation(code, lotteryList.get(i).getLotteryUrl());

    } else if ("weinisiren".equals(lotteryList.get(i).getSource())) {
      lotteryInformationService.addWeiNiSiRen(code, lotteryList.get(i).getLotteryUrl());

    } else if ("jinsha".equals(lotteryList.get(i).getSource())) {
      lotteryInformationService.addJSYL(code, lotteryList.get(i).getLotteryUrl());

    } else if ("hgc".equals(lotteryList.get(i).getSource())) {
      lotteryInformationService.addHuangCai(code, lotteryList.get(i).getLotteryUrl());
    } else if ("l8".equals(lotteryList.get(i).getSource())) {
      lotteryInformationService.addlblottery(code, lotteryList.get(i).getLotteryUrl());
    } else {
      log.error("添加"+code+"失败，找不到来源");
    }
  }
}
